package UI;

import android.content.Context;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

import java.util.Dictionary;
import java.util.Hashtable;

public class PopupMenuMaker  {
    public static PopupMenu MakePopupMenu(Context context, View view)
    {
        PopupMenu menu=new PopupMenu(context,view);
        menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                MenuItemClick(item);
                return false;
            }
        });
        return menu;
    }
    static Dictionary<String,IMenuSelectAction> actions=new Hashtable<>();

    public static void ApplyMenuItemCLick(String MenuText,IMenuSelectAction action)
    {
        actions.put(MenuText,action);
    }

    public  static  void MenuItemClick(MenuItem item)
    {
       String text= item.getTitle().toString();
       IMenuSelectAction action= actions.get(text);
       if(action!=null)
           action.Action(item);
    }
}
